package com.zxy.ziems.server.energy.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.ziems.server.constant.DateType;
import com.zxy.ziems.server.dto.DataQueryDto;
import com.zxy.ziems.server.energy.service.DataChartService;
import com.zxy.ziems.server.vo.ChartVo;
import com.zxy.ziems.server.vo.EnergyReportVo;
import com.zxy.ziems.server.vo.PieChartVo;
import com.zxy.ziems.server.vo.ReportVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName DataChartController
 * @Description
 * @Author 邓伟
 * @Date 2023/12/6 10:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/chart")
public class DataChartController {

    @Autowired
    private DataChartService dataChartService;

    /**
     * 能源数据统计-本周期数据环比
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/thisCycleData")
    public JsonResponse<ChartVo> thisCycleData(@Validated(value = DataQueryDto.Select.class) @RequestBody DataQueryDto dataQueryDto) {
        ChartVo chartVo = dataChartService.thisCycleData(dataQueryDto);
        return JsonResponse.SUCCESS(chartVo);
    }

    /**
     * 能源数据统计-上周期数据对比
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/lastCycleDataCompare")
    public JsonResponse<ChartVo> lastCycleDataCompare(@Validated(value = DataQueryDto.Select.class) @RequestBody DataQueryDto dataQueryDto) {
        ChartVo chartVo = null;
        if (!dataQueryDto.getQueryType().equals(DateType.HIS_YEAR)) {
            chartVo = dataChartService.lastCycleDataCompare(dataQueryDto);
        }
        return JsonResponse.SUCCESS(chartVo);
    }

    /**
     * 能源数据统计-本周期饼图
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/thisCycleDataPie")
    public JsonResponse<List<PieChartVo>> thisCycleDataPie(@Validated(value = DataQueryDto.Select.class) @RequestBody DataQueryDto dataQueryDto) {
        List<PieChartVo> list = dataChartService.thisCycleDataPie(dataQueryDto);
        return JsonResponse.SUCCESS(list);
    }

    /**
     * 能源数据对比-本周期数据环比柱状图
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/compareBarChart")
    public JsonResponse<ChartVo> compareBarChart(@RequestBody DataQueryDto dataQueryDto) {
        ChartVo chartVo = dataChartService.compareBarChart(dataQueryDto);
        return JsonResponse.SUCCESS(chartVo);
    }

    /**
     * 能源数据对比-本周期数据环比报表
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/compareChartReport")
    public JsonResponse<ReportVo> compareChartReport(@RequestBody DataQueryDto dataQueryDto) {
        ReportVo reportVo = dataChartService.compareChartReport(dataQueryDto);
        return JsonResponse.SUCCESS(reportVo);
    }

    /**
     * 点位数据统计--本周期数据环比
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/pointCompareLineChart")
    public JsonResponse<ChartVo> pointCompareLineChart(@RequestBody DataQueryDto dataQueryDto) {
        ChartVo chartVo = dataChartService.pointCompareLineChart(dataQueryDto);
        return JsonResponse.SUCCESS(chartVo);
    }

    /**
     * 点位(设备)数据统计--本周期数据环比
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/deviceCompareLineChart")
    public JsonResponse<ChartVo> deviceCompareLineChart(@RequestBody DataQueryDto dataQueryDto) {
        ChartVo chartVo = dataChartService.deviceCompareLineChart(dataQueryDto);
        return JsonResponse.SUCCESS(chartVo);
    }

    /**
     * 点位数据统计--本周期环比数据报表
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/pointCompareLineReport")
    public JsonResponse<ReportVo> pointCompareLineReport(@RequestBody DataQueryDto dataQueryDto) {
        ReportVo reportVo = dataChartService.pointCompareLineReport(dataQueryDto);
        return JsonResponse.SUCCESS(reportVo);
    }

    /**
     * 点位（设备）数据统计--本周期环比数据报表
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/deviceCompareLineReport")
    public JsonResponse<ReportVo> deviceCompareLineReport(@RequestBody DataQueryDto dataQueryDto) {
        ReportVo reportVo = dataChartService.deviceCompareLineReport(dataQueryDto);
        return JsonResponse.SUCCESS(reportVo);
    }

    /**
     * 能源数据报表
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/energyReport")
    public JsonResponse<EnergyReportVo> energyReport(@Validated(value = DataQueryDto.Select.class) @RequestBody DataQueryDto dataQueryDto) {
        EnergyReportVo energyReportVo = dataChartService.energyReport(dataQueryDto);
        return JsonResponse.SUCCESS(energyReportVo);
    }

    /**
     * 点位数据统计--本周期环比数据报表
     *
     * @param dataQueryDto
     * @return
     */
    @PostMapping("/pointReport")
    public JsonResponse<EnergyReportVo> pointReport(@RequestBody DataQueryDto dataQueryDto) {
        EnergyReportVo energyReportVo = dataChartService.pointReport(dataQueryDto);
        return JsonResponse.SUCCESS(energyReportVo);
    }
}
